package com.zyx.mpdemo.controller;

import com.zyx.mpdemo.common.resp.CommonResponse;
import com.zyx.mpdemo.model.req.BatchLearnedReq;
import com.zyx.mpdemo.model.req.CourseDetailReq;
import com.zyx.mpdemo.model.req.CourseListReq;
import com.zyx.mpdemo.model.vo.CourseDetailVO;
import com.zyx.mpdemo.model.vo.CourseInfoVO;
import com.zyx.mpdemo.model.vo.CourseListVO;
import com.zyx.mpdemo.service.ICourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 课程相关接口
 *
 * @author Yaxi.Zhang
 * @since 2023/1/26 08:52
 */
@Slf4j
@Controller
@ResponseBody
@RequestMapping("/course")
public class CourseController {

    @Resource
    private ICourseService courseService;

    /**
     * 查询所有课程名称以及章节号
     *
     * @return 所有课程名称以及章节号
     */
    @GetMapping("/course-infos")
    public CommonResponse<List<CourseInfoVO>> getCourseInfo() {
        return CommonResponse.success(courseService.getCourseInfo(), "查询所有课程名称以及章节号成功");
    }

    /**
     * 依据课程id查询课程列表
     */
    @PostMapping("/course-list")
    public CommonResponse<CourseListVO> getCourseList(@Validated @RequestBody CourseListReq courseListReq) {
        return CommonResponse.success(courseService.getCourseList(courseListReq), "查询课程列表成功");
    }

    /**
     * 查询课程详情
     */
    @PostMapping("/course-detail")
    public CommonResponse<List<CourseDetailVO>> getCourseDetail(@Validated @RequestBody CourseDetailReq courseDetailReq) {
        return CommonResponse.success(courseService.getCourseDetail(courseDetailReq), "查询课程详情成功");
    }

    /**
     * 批量修改课程为已学完
     */
    @PutMapping("/batch-learned")
    public CommonResponse<Void> batchLearned(@Validated @RequestBody BatchLearnedReq batchLearnedReq) {
        courseService.batchLearned(batchLearnedReq);
        return CommonResponse.success(null, "批量修改课程为已学完成功");
    }

}
